package com.rongc.client.freight.base.view.widget;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;

import com.flyco.dialog.utils.CornerUtils;
import com.flyco.dialog.widget.internal.BaseAlertDialog;
import com.rongc.client.freight.R;

/**
 * Created by Bruce on 2017/1/4.
 */
public class IDDialog extends BaseAlertDialog<IDDialog> {

    public IDDialog(Context context) {
        super(context);

        /** default value*/
        mTitleTextColor = ContextCompat.getColor(context, R.color.universal_text_primary);
        mTitleTextSize = 22f;
        mContentTextColor = ContextCompat.getColor(context,R.color.universal_text_primary);
        mContentTextSize = 17f;
        mLeftBtnTextColor = ContextCompat.getColor(context,R.color.universal_text_white);
        mRightBtnTextColor = ContextCompat.getColor(context,R.color.universal_text_white);

        mLeftBtnTextSize = 17f;
        mRightBtnTextSize = 17f;


        /** default value*/
    }

    @Override
    public View onCreateView() {
        /** title */
        mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        mLlContainer.addView(mTvTitle);

        /** btns */
        mLlBtns.setOrientation(LinearLayout.VERTICAL);
        mTvBtnLeft.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
        ((LinearLayout.LayoutParams)mTvBtnLeft.getLayoutParams()).setMargins(dp2px(30),dp2px(10),dp2px(30),dp2px(10));
        mTvBtnLeft.setPadding(dp2px(10),dp2px(10),dp2px(10),dp2px(10));
        mLlBtns.addView(mTvBtnLeft);

//
//        mTvBtnMiddle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
//        ((LinearLayout.LayoutParams)mTvBtnMiddle.getLayoutParams()).setMargins(dp2px(10),dp2px(10),dp2px(10),dp2px(10));
//        mLlBtns.addView(mTvBtnMiddle);


        mTvBtnRight.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
        ((LinearLayout.LayoutParams)mTvBtnRight.getLayoutParams()).setMargins(dp2px(30),dp2px(10),dp2px(30),dp2px(10));
        mTvBtnRight.setPadding(dp2px(10),dp2px(10),dp2px(10),dp2px(10));
        mLlBtns.addView(mTvBtnRight);

        mLlContainer.addView(mLlBtns);


        /** content */
        mTvContent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        mLlContainer.addView(mTvContent);

        return mLlContainer;
    }

    @Override
    public void setUiBeforShow() {
        super.setUiBeforShow();

        float radius = dp2px(mCornerRadius);
        mTvTitle.setPadding(dp2px(18), dp2px(18), dp2px(18), dp2px(18));

        mLlContainer.setBackgroundDrawable(CornerUtils.cornerDrawable(mBgColor, radius));

        mTvBtnLeft.setBackgroundDrawable(CornerUtils.btnSelector(radius, ContextCompat.getColor(getContext(), R.color.app_color_nor), mBtnPressColor, -2));
        mTvBtnRight.setBackgroundDrawable(CornerUtils.btnSelector(radius, ContextCompat.getColor(getContext(), R.color.app_color_nor), mBtnPressColor, -2));
        mTvBtnMiddle.setBackgroundDrawable(CornerUtils.btnSelector(radius, ContextCompat.getColor(getContext(), R.color.app_color_nor), mBtnPressColor, -1));


        mTvTitle.setGravity(Gravity.CENTER);
        mTvContent.setLines(1);
        mTvContent.setGravity(Gravity.CENTER);
        mTvContent.setPadding(dp2px(0), dp2px(0), dp2px(0), dp2px(20));

        /** title */
        mTvTitle.setText(R.string.main_pop_choise_title);

        /**btns*/
        mTvBtnLeft.setText(R.string.main_pop_choise_shipper);
        mTvBtnRight.setText(R.string.main_pop_choise_carrier);
        mTvBtnMiddle.setVisibility(View.GONE);

        /** content */
        mTvContent.setText(R.string.main_pop_choise_tip);

    }

    @Override
    public void onBackPressed() {
        if(!mCancel) return;
        super.onBackPressed();
    }
}
